<?php
$adresse = urldecode($_GET['u']);
$titre = $_GET['t'];
$selection = $_GET['s'];
$username = $_GET['user'];
$password = $_GET['pass'];



$sUrl=$adresse;
$image = '';
$sContent=file_get_contents($sUrl,FALSE,NULL);
$aParse_url=parse_url($sUrl);
$sScheme=$aParse_url['scheme'].'://';
$sHost=$aParse_url['host'];
$sMotif='#<img.+?src="(.+?)"#';
preg_match_all($sMotif,$sContent,$aResults);
$iNb_results=count($aResults[1]);
//echo '<p>Il y a ',$iNb_results,' image(s) sur la page ',$sUrl,'</p>';
for($i=0;$i<=$iNb_results-1;$i++){
    if(substr($aResults[1][$i],0,strlen($sScheme)+strlen($sHost))!==$sScheme.$sHost and substr($aResults[1][$i],0,1)==="/"){
        $image .= '\''.$sScheme.$sHost.$aResults[1][$i].'\', ';
    }else{
        $image .= '\''.$aResults[1][$i].'\', ';
    }
}
$image = substr($image, 0, -2);

$embed = '';
if(preg_match('#http://(.+).youtube.com/watch#i', $adresse))
{
$id = preg_replace('#http://(.+).youtube.com/watch\?v=([a-zA-Z0-9_])#i', '$2', $adresse);
//$adresse2 = preg_replace('#http://[a-z0-9._/-]+#i', '<a href="$0">$0</a>', $adresse2);
//echo $id;
$embed = htmlentities('<object width="425" height="355"><param name="movie" value="http://www.youtube.com/v/OXJ5LvLgONg&hl=fr"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'.$id.'&hl=fr" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"></embed></object>');
//echo $embed;

include('youtube.php');


}

elseif(preg_match('#http://(.+).dailymotion.com/#i', $adresse))
{
$id = preg_replace('#(.+)/video/(.+)#i', '$2', $adresse);
$id = explode('_', $id);
$id = $id[0];
//echo $id;
$embed = htmlentities('<div><object width="420" height="336"><param name="movie" value="http://www.dailymotion.com/swf/'.$id.'&v3=1&related=0"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed src="http://www.dailymotion.com/swf/'.$id.'&v3=1&related=0" type="application/x-shockwave-flash" width="420" height="336" allowFullScreen="true" allowScriptAccess="always"></embed></object></div>');
//echo $embed;
}

elseif(preg_match('#http://video.google.(.+)/videoplay#i', $adresse))
{
$id = preg_replace('#http://video.google.(.+)/videoplay\?docid=([a-zA-Z0-9_-])#i', '$2', $adresse);
//echo $id;
$embed = htmlentities('<embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId='.$id.'&hl=fr"> </embed>');
//echo $embed;
//exit;
}

?>




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    	<title>Ecrire sur Skyrock Blog</title>
<style type="text/css">
    	    body {
    	        background-color: #f3f3f3;
    	        margin: 0px;
    	        padding: 0px;
    	        font: Normal 13px 'Lucida Grande', Verdana, Helvetica, sans-serif;
    	    }
    	    
    	    a {
    	        color: #007BFF;
    	        outline-width: 0px;
    	        -moz-outline-width: 0px;
    	    }
    	        	    
    	    ul#navigation {
    	        position: absolute;
    	        left: 20px;
    	        top: 15px;
    	        list-style-type: none;
    	        margin: 0px;
    	        padding: 0px;
    	    }
    	    
    	        ul#navigation li {
    	            float: left;
    	            width: 60px;
    	            height: 25px;
    	            font-size: 12px;
    	            line-height: 25px;
    	            background-color: #d5d5d5;
    	            text-align: center;
    	            margin-right: 5px;
    	            font-weight: bold;
        	    }
        	    
            	    ul#navigation li a {
            	        text-decoration: none;
            	        color: #444;
            	    }
            	    
            	    ul#navigation li.active {
            	        background-color: #fff;
        	        }
        	        
        	        ul#navigation li.disabled {
            	        background-color: #e5e5e5;
            	        color: #ccc;
        	        }
    	    
    	    div#container {
    	        background-color: #fff;
    	        border-right: solid 1px #ddd;
    	        border-bottom: solid 1px #ddd;
    	        position: absolute;
    	        height: 450px;
    	        top: 40px;
    	        left: 15px;
                right: 15px;
                padding: 0px 15px 0px 15px;
                overflow: hidden;
    	    }
    	    
    	        div#container h2 {
    	            margin: 15px 0px 0px 0px;
    	            font-size: 15px;
    	        }
        	    
        	        div#container h2 span.optional {
        	            font-size: 10px;
        	            color: #bbb;
        	            font-style: italic;
        	            font-weight: normal;
        	        }
    	    
    	        div#container form {
    	            margin: 0px;
        	        padding: 0px;
    	        }
    	        	    
    	    textarea, input.text {
    	        width: 374px;
    	        font: Normal 12px 'Lucida Grande', Verdana, Helvetica, sans-serif;
    	        border: solid 1px #ccc;
    	        background-color: #f4f4f4;
    	        padding: 2px;
    	        margin: 0px;
    	    }
    	</style>

    	
    	<!--[if IE]>
        	<style type="text/css">
        	    div#container {
        	        height: 377px;
        	    }
        	</style>
    	<![endif]-->
    	
    	<script type="text/javascript">
    	    var saving = false;
    	
    	    function activate_nav_tab(id) {
    	        document.getElementById('nav_regular').style.backgroundColor = '#d5d5d5';
    	        document.getElementById('nav_photo').style.backgroundColor   = '#d5d5d5';
    	        document.getElementById('nav_quote').style.backgroundColor   = '#d5d5d5';
    	        document.getElementById('nav_video').style.backgroundColor   = '#d5d5d5';
    	        
    	        document.getElementById('nav_' + id).style.backgroundColor   = '#fff';
    	        
    	        document.getElementById('regular_form').style.display        = 'none';
    	        document.getElementById('photo_form').style.display          = 'none';
    	        document.getElementById('quote_form').style.display          = 'none';
    	        document.getElementById('video_form').style.display          = 'none';
    	        
    	        document.getElementById(id + '_form').style.display          = '';
    	        
    	        
    	        return false;
    	    }
    	</script>    	
    </head>
    <body>
                <ul id="navigation">
                            <li <?php if($embed == '') echo 'class="active"'; ?> id="nav_regular">
                                            <a href="#" onclick="this.blur(); return activate_nav_tab('regular');">Article</a>
                                    </li>

                            <li id="nav_photo">
                                            <a href="#" onclick="this.blur(); return activate_nav_tab('photo');">Photo</a>
                                    </li>
                            <li id="nav_quote">
                                            <a href="#" onclick="this.blur(); return activate_nav_tab('quote');">Citation</a>
                                    </li>

                            <li <?php if($embed != '') echo 'class="active"'; ?> id="nav_video">
                                            <a href="#" onclick="this.blur(); return activate_nav_tab('video');">Gadget</a>
                                    </li>
                    </ul>

        <div id="container">
            


<!-- Regular -->
<form action="envoi.php?type=article" method="post" id="regular_form" <?php if($embed != '') echo 'style="display:none;"'; ?>>
    <input type="hidden" name="username" value="<?php echo $username; ?>"/>
    <input type="hidden" name="password" value="<?php echo $password; ?>"/>
    <input type="hidden" name="v" value="3"/>

    <h2>Titre <span class="optional">(optionnel)</span></h2>
    <input type="text" name="article_title" id="link_post_one" class="text"
    style="font-size:18px;"/>

    <div style="margin-top:15px; width:380px;">
		<h2>Article <span class="optional"></span></h2>
        <textarea name="article_article" id="regular_post_two"
        style="height:200px;">&lt;a href="<?php echo $adresse; ?>"&gt;<?php echo $titre; ?>&lt;/a&gt;</textarea>

    </div>                
        <div style="margin-top:15px;">
        <input type="submit" value="Ajouter l'article"
        onclick="if (saving == true) return false; this.value='Saving...'; saving = true;"/>
        
            </div>
</form>

<!-- Photo -->
    <form action="envoi.php?type=photo" method="post" id="photo_form"
    style="display:none;">
		<input type="hidden" name="username" value="<?php echo $username; ?>"/>
		<input type="hidden" name="password" value="<?php echo $password; ?>"/>
		
    <h2>Titre <span class="optional">(optionnel)</span></h2>
    <input type="text" name="photo_title" id="link_post_one" class="text"
    style="font-size:18px;"/>
                            <h2>Texte <span class="optional">(optionnel)</span></h2>

                <div style="width: 380px;">
                    <textarea name="photo_article" id="photo_post_two"
                    style="height:80px;">Source iconographique : &lt;a href="<?php echo $adresse; ?>"&gt;<?php echo $titre; ?>&lt;/a&gt;</textarea>
                </div>
            
                <h2>Adresse de la photo</h2>
                <input name="photo_image" id="photo_src" class="text" onkeydown="pick(0);"/>
        
                                    <style type="text/css">
                        #img_container img {
                            width:          75px;
                            height:         75px;
                            padding:        2px;
                            background-color: #f4f4f4;
                            margin-right:   7px; 
                            margin-bottom:  7px; 
                            cursor:         pointer;
                        }
                    </style>
                    <div id="img_container" style="border:solid 1px #ccc; background-color:#f4f4f4;
                    padding:5px; width:368px; margin-top:10px; overflow:auto; height:100px;">

                        <script type="text/javascript">
                        var img, img_tag, aspect, w, h, skip, i;
                        var src = [<?php echo $image; ?>];
                        var last = null;
                
                        function pick(img)
                        {
                            if (last) last.style.backgroundColor = '#f4f4f4';
                            if (img) {
                                document.getElementById('photo_src').value = img.src;
                                img.style.backgroundColor = '#44f';
                            }
                            last = img;
                            return false;
                        }
                
                        for (i = 0; i < src.length; i++) {
                            img = new Image();
                            img.src = src[i];
                            img_attr = 'id="img' + i + '" onclick="pick(this);"';
                            skip = false;
                            if (img.width && img.height) {
                                if (img.width * img.height < 2500) skip = true;
                        
                                aspect = img.width / img.height;
                                if (aspect > 1) {
                                    // Image is wide
                                    scale = 75 / img.width;
                                } else {
                                    // Image is tall or square
                                    scale = 75 / img.height;
                                }
                                if (scale < 1) {
                                    w = parseInt(img.width * scale);
                                    h = parseInt(img.height * scale);
                                } else {
                                    w = img.width;
                                    h = img.height;
                                }
                                img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
                            }
                            if (! skip) document.write('<img src="' + img.src + '" ' + img_attr + '/>');
                        }
                        </script>
                    </div>
                                
                <div style="margin-top:15px;">
        <input type="submit" value="Ajouter la photo"
        onclick="if (saving == true) return false; this.value='Saving...'; saving = true;"/>
        
            </div>
            </form>

<!-- Quote -->
<form action="envoi.php?type=citation" method="post" id="quote_form"
style="display:none;">
	<input type="hidden" name="username" value="<?php echo $username; ?>"/>
	<input type="hidden" name="password" value="<?php echo $password; ?>"/>
    
			
    <h2>Titre <span class="optional">(optionnel)</span></h2>
    <input type="text" name="citation_title" id="link_post_one" class="text"
    style="font-size:18px;"/>
	
    <h2>Quote</h2>
    <textarea name="citation_citation" id="quote_post_one"
    style="height:80px;"/><?php echo $selection; ?></textarea>

    <h2>Source <span class="optional">(optional)</span></h2>
    <div style="width: 380px;">
        <textarea name="citation_source" id="quote_post_two"
        style="height:80px;">Source : &lt;a href="<?php echo $adresse; ?>"&gt;<?php echo $titre; ?>&lt;/a&gt;</textarea>

    </div>

    <script type="text/javascript">render_editor('quote_post_two', 'rich', 1);</script>    <input type="hidden" id="quote_post_two_is_rich_text" name="is_rich_text[two]" value="0"/>

        <div style="margin-top:15px;">
        <input type="submit" value="Ajouter la citation"
        onclick="if (saving == true) return false; this.value='Saving...'; saving = true;"/>
        
            </div>
</form>


<!-- Video -->
<form action="envoi.php?type=video" method="post" id="video_form" <?php if($embed == '') echo 'style="display:none;"'; ?>>

	<input type="hidden" name="username" value="<?php echo $username; ?>"/>
	<input type="hidden" name="password" value="<?php echo $password; ?>"/>

	    <h2>Titre <span class="optional">(optionnel)</span></h2>
    <input type="text" name="video_title" id="link_post_one" class="text" value="<?php echo $titre_video; ?>"
    style="font-size:18px;"/>
	
            <h2>Code du gadget</h2>
        <textarea name="video_embed" id="video_post_one"
        style="height:80px;"/><?php echo $embed; ?></textarea>
        
        <h2>Article <span class="optional">(optionnel)</span></h2>

<?php if($description_video == '')
{
?>
        <div style="width: 380px;">
            <textarea name="video_article" id="video_post_two"
            style="height:80px;"/>&lt;a href="<?php echo $adresse; ?>"&gt;<?php echo $titre; ?>&lt;/a&gt;</textarea>
        </div>
<?php
}
else
{
?>
        <div style="width: 380px;">
            <textarea name="video_article" id="video_post_two"
            style="height:80px;"/>&lt;a href="<?php echo $adresse; ?>"&gt;<?php echo $titre_video; ?>&lt;/a&gt; par &lt;a href="http://fr.youtube.com/user/<?php echo $auteur_video; ?>"&gt;<?php echo $auteur_video; ?>&lt;/a&gt;
			&lt;a href="<?php echo $download; ?>"&gt;Télécharger la vidéo&lt;/a&gt;
			</textarea>
        </div>
<?php		
}
?>               
        <div style="margin-top:15px;">
        <input type="submit" value="Ajouter la vidéo"
        onclick="if (saving == true) return false; this.value='Saving...'; saving = true;"/>
        
            </div>

</form>               
        </div>
    </body>
</html>